#include <algorithm>
#include <cstdio>
using namespace std;

#include <unistd.h>
#include <fcntl.h>

int propTester(int (*func)(unsigned char *), char *filename) {
	int retval;
	int device_fd;
	unsigned char sbox[16];
	
	// Open file
	device_fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 
			 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
	if(device_fd == -1) {
		 perror("Error opening output");
		 return 1;
	}

	// Create initial sbox
	for(int i = 0; i < 16; ++i)
		sbox[i] = i;
	
	// Test all permutations
	do {
		if(func(sbox) == 0) {
			retval = write(device_fd, sbox, sizeof(char[16]));
			if(retval == -1) {
				perror("Error while writing buffer");
				return 1;
			}
		}
	} while(next_permutation(sbox, sbox + 16) == true);

	return 0;
}
